package net.joke.base.systems;

import net.joke.base.EntityFactory;
import net.joke.base.components.Renderable;
import net.joke.base.components.Stats;

import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.EntityProcessingSystem;

public class StatsProcesSystem extends EntityProcessingSystem {

	public StatsProcesSystem() {
		super(Stats.class);
	}
	
	private ComponentMapper<Stats> statsMapper;
	private ComponentMapper<Renderable> renderableMapper;
	
	@Override
	protected void initialize() {
		super.initialize();
		statsMapper = new ComponentMapper<Stats>(Stats.class, world); 
		renderableMapper = new ComponentMapper<Renderable>(Renderable.class, world); 
	}

	@Override
	protected void process(Entity e) {
		Stats s = statsMapper.get(e);
		if (s.isStatDirty) {
			s.actualStat.maxLife = s.baseStat.maxLife;
			s.actualStat.currentLife = s.baseStat.currentLife;
			s.actualStat.recoverHp = s.baseStat.recoverHp;
			s.actualStat.speed = s.baseStat.speed;
			s.actualStat.hitSpeed = s.baseStat.hitSpeed;
			s.isStatDirty = false;
		}
		// TODO recoverLife mi ritorna gli ev punti recuperati, devo disegnarli !
		// Idea .. entity ScreenPopText, 
		// la creiamo da qua, 
		// Le diamo il testo da visualizzare
		// Disegna ed anima il testo a video e muore.
		float howMany = s.recoverLife(world.getDelta());
		if (howMany > 0.0f) {
			Renderable r = renderableMapper.get(e);
			if (r != null) {
				EntityFactory.getInstance().greenPoints(world, r.andRenderable.owner, r.andRenderable.sprite.getX(), r.andRenderable.sprite.getY() - 10, howMany);
			}
		}
		
		// Global Cooldown reduction
		s.cooldown(world.getDelta());
		
	}

}
